package com.xc.file.enums;

import com.xc.file.exception.OperateException;
import com.xc.file.exception.ServerException;

/**
 * <p>项目名称: Stars</p>
 * <p>描述: 故障代码</p>
 * <P>创建人:小程 </p>
 * <P>创建人邮箱: 779943476@qq.com</p>
 * <p>创建时间: 2019/12/10</p>
 *
 * @version v1.0
 */
public enum FailCode {
    OTHER_EXCEPTION,
    //服务器异常
    FEIGN_REQUEST_ERROR("sf001", "feign请求错误！"),
    SERVER_EXCEPTION("sf002", "服务器异常,请联系管理员！"),
    RENAME_FAIL("sf003", "重命名失败！"),
    DELETE_FILE_FAIL("sf004", "删除文件失败！"),
    FILE_EXIST("sf005", "文件已存在！"),
    FILE_NOT_EXIST("sf006", "文件不存在！"),
    FILE_INFO_DATA_ERROR("sf007", "文件信息数据错误！"),
    INSUFFICIENT_SPACE("sf008", "服务器硬盘空间不足！"),
    TEMP_FILE_CREATE_FAIL("sf006", "临时文件创建失败！"),
    CREATE_INIT_FOLDER("sf007", "创建初始化目录失败"),
    //操作异常
    NOT_HAVE_AUTHORITY("of001", "你没有权限访问！"),
    FILE_DATA_ERROR("of002", "你上传的文件数据错误！"),
    FILE_NOT_EMPTY("of003", "你上传的文件不能为空！"),
    HASH_ERROR("of004", "你的文件hash值错误！"),
    DOWNLOAD_FILE_NOT_EXIST("of005", "你下载的文件不存在！"),
    UPLOAD_FILE_OVERTIME("0f006", "上传文件超时！");


    /**
     * 错误code
     */
    private String code;
    /**
     * 消息
     */
    private String message;

    FailCode() {
    }

    FailCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public OperateException getOperateException() {
        return new OperateException(this.code, this.getMessage());
    }

    public ServerException getServerException() {
        return new ServerException(this.code, this.getMessage());
    }

    public Exception exceptionHandle(String code, String message) {
        if ("o".equals(code.substring(0, 1))) {
            return new OperateException(code, message);
        } else {
            return new ServerException(code, message);
        }
    }
}
